package com.sztle.admodule.apiprocessor;

import android.app.Activity;
import android.widget.FrameLayout;

import com.sztle.admodule.GmAdManager;
import com.sztle.admodule.IShowListener;
import com.sztle.admodule.bean.AdReportInfo;
import com.sztle.admodule.handler.NativeHandler;
import com.sztle.admodule.control.event.SzAdEvents;
import com.sztle.admodule.control.manager.ControlManager;
import com.sztle.admodule.control.utils.UserDeviceUtils;

public class OutNativeApi {

    private static boolean isShowed = false;
    public static void showNativeAd(Activity activity, FrameLayout adContainer, String sceneName) {
        ControlManager.triggerQueryAdjust();
        if(!GmAdManager.isAdSdkReady()){
            return;
        }
        if(UserDeviceUtils.isGMore() && isShowed){
            return;
        }
        NativeHandler.loadAndShow(activity, adContainer, new IShowListener() {
            @Override
            public void onAdShow(String ecpm) {
                isShowed = true;
                ControlManager.reportAdLog(SzAdEvents.show_native,new AdReportInfo(ecpm,sceneName));
            }
        });
    }

    public static void showNativeAd(Activity activity, FrameLayout adContainer, String sceneName,IShowListener showListener) {
        ControlManager.triggerQueryAdjust();
        if(!GmAdManager.isAdSdkReady()){
            return;
        }
        if(UserDeviceUtils.isGMore() && isShowed){
            return;
        }
        NativeHandler.loadAndShow(activity, adContainer, new IShowListener() {
            @Override
            public void onAdShow(String ecpm) {
                if(showListener != null){
                    showListener.onAdShow(ecpm);
                }
                isShowed = true;
                ControlManager.reportAdLog(SzAdEvents.show_native,new AdReportInfo(ecpm,sceneName));
            }

            @Override
            public void onFinalEnd(boolean result) {
                if(showListener != null){
                    showListener.onFinalEnd(result);
                }
            }
        });
    }
}
